package vista;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ContainerAdapter;
import java.util.List;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import controlador.ControladorAC;
import dto.EmpleadoDTO;
import dto.ProductoDTO;
import dto.SucursalDTO;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class AgregarTarea extends javax.swing.JFrame {
	private JLabel jLabel1;
	private JLabel jLabel3;
	private JLabel jLabel4;
	private JComboBox sucursal;
	private JTextField estado;
	private JSeparator jSeparator2;
	private JButton cancelar;
	private JButton aceptar;
	private JLabel jLabel5;
	private JLabel jLabel7;
	private JTextField cantidad;
	private JLabel jLabel6;
	private JTextField horas;
	private JSeparator jSeparator1;
	private JComboBox productos;
	private List<SucursalDTO> sucursalesL;
	private List<ProductoDTO> productosL;

	/**
	 * Auto-generated main method to display this JFrame
	 */
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				AgregarTarea inst = new AgregarTarea(null);
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}

	public AgregarTarea(EmpleadoDTO e2) {
		super();
		initGUI(e2);
	}

	private void initGUI(final EmpleadoDTO e2) {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			this.setLocationRelativeTo(null);
			getContentPane().setLayout(null);
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("Tarea");
				jLabel1.setBounds(31, 13, 82, 16);
			}
			{
				jLabel3 = new JLabel();
				getContentPane().add(jLabel3);
				jLabel3.setText("Producto");
				jLabel3.setBounds(47, 68, 66, 16);
			}
			{
				
				productos = new JComboBox<String>();
				getContentPane().add(productos);
				productosL = ControladorAC.getInstancia().listarProductosElaborados();
				productos.setBounds(165, 65, 207, 23);
				for(ProductoDTO p: productosL){
					productos.addItem(p.getNombre());
				}
			}
			{
				jLabel4 = new JLabel();
				getContentPane().add(jLabel4);
				jLabel4.setText("Sucursal");
				jLabel4.setBounds(51, 155, 56, 16);
			}
			{
			
				sucursal = new JComboBox<String>();
				getContentPane().add(sucursal);
				sucursalesL = ControladorAC.getInstancia().listarSucursales();
				sucursal.setBounds(165, 148, 207, 23);
				for(SucursalDTO s: sucursalesL){
					sucursal.addItem(s.getNombre());
				}
			}
			{
				jSeparator1 = new JSeparator();
				getContentPane().add(jSeparator1);
				jSeparator1.setBounds(0, 40, 561, 10);
			}
			{
				jLabel5 = new JLabel();
				getContentPane().add(jLabel5);
				jLabel5.setText("Hs Requeridas");
				jLabel5.setBounds(31, 198, 113, 16);
			}
			{
				horas = new JTextField();
				getContentPane().add(horas);
				horas.setBounds(165, 195, 207, 23);
			}
			{
				jLabel6 = new JLabel();
				getContentPane().add(jLabel6);
				jLabel6.setText("Cantidad");
				jLabel6.setBounds(47, 112, 60, 16);
			}
			{
				cantidad = new JTextField();
				getContentPane().add(cantidad);
				cantidad.setBounds(165, 109, 207, 23);
			}
			{
				jLabel7 = new JLabel();
				getContentPane().add(jLabel7);
				jLabel7.setText("Estado");
				jLabel7.setBounds(63, 242, 56, 16);
			}
			{
				aceptar = new JButton();
				getContentPane().add(aceptar);
				aceptar.setText("Aceptar");
				aceptar.setBounds(275, 304, 97, 23);
				aceptar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						SucursalDTO suc = null;
						ProductoDTO prod = null;
						
						for(SucursalDTO s : sucursalesL){
							if(s.getNombre().equalsIgnoreCase((String)sucursal.getSelectedItem())){
								suc = s;
							}
						}
						for(ProductoDTO p : productosL){
							if(p.getNombre().equalsIgnoreCase((String)productos.getSelectedItem())){
								prod = p;
							}
						}
						
						boolean resp = ControladorAC.getInstancia().altaTarea(e2,suc,prod,Integer.parseInt(cantidad.getText()),estado.getText(),Integer.parseInt(horas.getText()));
						
						if(resp == true){
							JOptionPane.showMessageDialog(null, "Se dio de alta una tarea para la sucursal " + suc.getNombre());
						}
						
						dispose();
					}
				});
			}
			{
				cancelar = new JButton();
				getContentPane().add(cancelar);
				cancelar.setText("Cancelar");
				cancelar.setBounds(388, 304, 91, 23);
				cancelar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						dispose();
					}
				});
			}
			{
				jSeparator2 = new JSeparator();
				getContentPane().add(jSeparator2);
				jSeparator2.setBounds(0, 282, 585, 10);
			}
			{
				estado = new JTextField();
				getContentPane().add(estado);
				estado.setText("Activa");
				estado.setEditable(false);
				estado.setBounds(165, 242, 207, 23);
			}
			pack();
			this.setSize(515, 386);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
